<?
// Session.php
// written by: David Fudge [ rkstar@mac.com ]
// created on: November 6, 2008
// last modified: November 8, 2008
//
// description:
// this is merely a simple user interface to interact with the global $_SESSION
// variable/s
//
//session_start();

// load dependencies here
ed::load("Core.Error");
ed::load("Data.Data");

class Session
{
	// constructor
	public function __constructor()
	{
		global $_SESSION;
		// add each session var to the object
		$vars = get_object_vars($_SESSION);
		while( list($k,$v) = each($vars) ) { $this->$k = $v; }
	}

	// add a variable to the session
	public function add( $name, $value ) { $this->$name = $value; $this->save(); }
	// get rid of a variable from session
	public function remove( $name ) { unset($this->$name); }

	// save the session in a db
	public function save()
	{
/*
		global $_SESSION;
		$_SESSION = get_object_vars($this);
		// start a data object and encode the session for storage
		// in a database
		$d = new Data();
		$d->setDBTable(SESSIONTABLE);
		$d->setValue("session",session_encode());
		$d->setValue("id",SID);
		$d->setAuthMethod("id",SID);
		$d->setLimit(1);
		$d->update();
*/
	}

	// destroy the session
	public function destroy()
	{
		// first, delete the session from the db
		$d = new Data();
		$d->setDBTable(SESSIONTABLE);
		$d->setAuthMethod("id",SID);
		$d->setLimit(1);
		$d->delete();
		// destroy the session
		session_destroy();
	}
}
?>